﻿using System;
using System.Collections.Generic;
using Hn.Command;
using Hn.Database.Enum;
using MSocketCore.MSocket;
using SuperSocket;

namespace MSocketCore.Cmd
{
    public class PacketHelper
    {
        /// <summary>
        ///     确认包
        /// </summary>
        /// <param name="session"></param>
        /// <param name="info"></param>
        public static void Confirm(MySession session, MyPackage info)
        {
            var requestInfo = new MyPackage();
            requestInfo.Control = 0x0B; //主站下发 最高位清零;
            requestInfo.Sn = info.Sn;
            requestInfo.Afn = 0x00;
            requestInfo.PSeq = (byte)((info.PSeq + 1) & 0xf);
            requestInfo.Pn = info.Pn;
            requestInfo.Region = info.Region;
            //requestInfo.SEQ = 0x61; //贞序列号	7表示主站必须应答，6表示主站不需应答;
            requestInfo._Fn = 1;
            requestInfo.Content = null;
            var buff = requestInfo.Packet();
            session.SendAsync(buff);
        }


        /// <summary>`
        ///     确认包
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public static void ConfirmTime(MySession session, MyPackage info)
        {
            var packet = new MyPackage()
            {
                Sn = info.Sn,
                Afn = (byte)AFN.Control,
                _Fn = 31
            };
            var content = new List<byte>();
            content.AddRange(CmdHelper.GetBCD_A1(DateTime.Now));
            packet.Content = content.ToArray();
            var buff = packet.PacketPw();
            session.SendAsync(buff);
        }
    }
}
